<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>另一个iframe页面</title>
  </head>
  <body>
    <div>
      请输入用户主页id：<input type="text" />
      <button onclick="onBtnClick()">转跳至b站指定用户主页</button>
    </div>
    <script>
      function onBtnClick() {
        console.log(window.parent);
        const input = document.querySelector("input");
        const userId = input.value;
        const params = {
          targetUrl: "https://space.bilibili.com",
          userId,
        };
        window.parent.postMessage(params, "*");
      }
    </script>
  </body>
</html>
